### This script was written by Eric Deal, 06.22.2020
### Script should be run with python 3

#%%
import numpy as np, pandas as pd

mass_beaker_plus_water = {'tg': 623/1e3, 'sf': 607.5/1e3, 'ng2': 615/1e3, 'ng3': 619/1e3, 'ng4': 609/1e3, 'ng5': 611/1e3} # kg
dmass_beaker_plus_water = 0.0005 # grams

initial_vol_water = {'tg': 504.4/1e6, 'sf': 488.88/1e6, 'ng2': 496.39/1e6, 'ng3': 500.4/1e6, 'ng4': 490.38/1e6, 'ng5': 492.38/1e6} # m^3
dinitial_vol_water = 5e-6 # mL

mass_beaker_water_grains = {'tg': 965.5/1e3, 'sf': 840/1e3, 'ng2': 846/1e3, 'ng3': 816.5/1e3, 'ng4': 827/1e3, 'ng5': 793/1e3} # mass with 1000 grains (kg)
dmass_beaker_water_grains = 0.0005 # (kg)

vol_water_grains = {'tg': 642.14/1e6, 'sf': 572.14/1e6, 'ng2': 597.14/1e6, 'ng3': 572.14/1e6, 'ng4': 577.14/1e6, 'ng5': 567.14/1e6} # volume with 1000 grains (m^3)
dvol_water_grains = 5e-6 # (mL)

grains = ['tg', 'sf', 'ng2', 'ng3', 'ng4', 'ng5']
vol_grains = {grain: (vol_water_grains[grain] - initial_vol_water[grain]) for grain in grains}
dvol_grains = {grain: (np.sqrt(dvol_water_grains**2 + dinitial_vol_water**2)) for grain in grains}
vol_grain = {grain: (vol_water_grains[grain] - initial_vol_water[grain])/1e3 for grain in grains}
dvol_grain = {grain: (np.sqrt(dvol_water_grains**2 + dinitial_vol_water**2))/1e3 for grain in grains}

mass_grains = {grain: (mass_beaker_water_grains[grain] - mass_beaker_plus_water[grain]) for grain in grains}
dmass_grains = {grain: (np.sqrt(dmass_beaker_water_grains**2 + dmass_beaker_plus_water**2)) for grain in grains}
mass_grain = {grain: (mass_beaker_water_grains[grain] - mass_beaker_plus_water[grain])/1e3 for grain in grains}
dmass_grain = {grain: (np.sqrt(dmass_beaker_water_grains**2 + dmass_beaker_plus_water**2))/1e3 for grain in grains}


ro_grains = {grain: mass_grains[grain] / vol_grains[grain] for grain in grains} # (kg/m^3)
dro_grains = {grain: ro_grains[grain] * np.sqrt((dmass_beaker_water_grains/mass_beaker_water_grains[grain])**2 + (dmass_beaker_plus_water/mass_beaker_plus_water[grain])**2) for grain in grains}
print(mass_grains, dmass_grains, vol_grains, dvol_grains, ro_grains, dro_grains)

df = pd.DataFrame({
                'grain_mass': mass_grain,'dgrain_mass': dmass_grain,
                'total_grain_ro': ro_grains, 'dtotal_grain_ro': dro_grains,
                'grain_vol': vol_grain,'dgrain_vol': dvol_grain})

df.to_csv('1_var_density_2022.csv')

# %%
